Attribute VB_Name = "modLastIID"
'***************************************************************
' (c) Copyright 2000 Matthew J. Curland
'
' This file is from the CD-ROM accompanying the book:
' Advanced Visual Basic 6: Power Techniques for Everyday Programs
'   Author: Matthew Curland
'   Published by: Addison-Wesley, July 2000
'   ISBN: 0-201-70712-8
'   http://www.PowerVB.com
'
' You are entitled to license free distribution of any application
'   that uses this file if you own a copy of the book, or if you
'   have obtained the file from a source approved by the author. You
'   may redistribute this file only with express written permission
'   of the author.
'
' This file depends on:
'   References:
'     VBoostTypes6.olb (VBoost Object Types (6.0))
'     VBoost6.Dll (VBoost Object Implementation (6.0)) (optional)
'   Files:
'     VBoost.Bas (optional)
'   Minimal VBoost conditionals:
'     VBOOST_INTERNAL = 1 : VBOOST_CUSTOM = 1
'   Conditional Compilation Values:
'     NOVBOOST = 1 'Removes VBoost dependency
'
' This file is discussed in Chapter 8.
'***************************************************************
Option Explicit

Private Type LastIIDVTable
    VTable(2) As Long
End Type
Private m_VTable As LastIIDVTable
Private m_pVTable As Long

Public Type LastIID
    pVTable As Long
    QIThis As IUnknown
    IID As VBGUID
End Type

Public Sub InitLastIID(LastIID As LastIID)
    If m_pVTable = 0 Then
        With m_VTable
            .VTable(0) = FuncAddr(AddressOf QueryInterface)
            .VTable(1) = FuncAddr(AddressOf AddRefRelease)
            .VTable(2) = .VTable(1)
            m_pVTable = VarPtr(.VTable(0))
        End With
    End If
    With LastIID
        .pVTable = m_pVTable
        #If NOVBOOST Then
            CopyMemory .QIThis, VarPtr(.pVTable), 4
        #Else
            VBoost.Assign .QIThis, VarPtr(.pVTable)
        #End If
    End With
End Sub

Private Function QueryInterface(This As LastIID, riid As VBGUID, pvObj As Long) As Long
    This.IID = riid
    pvObj = 0
    QueryInterface = &H80004002 'E_NOINTERFACE
End Function
Private Function AddRefRelease(This As LastIID) As Long
    'Nothing to do
End Function
Private Function FuncAddr(ByVal pfn As Long) As Long
    FuncAddr = pfn
End Function
